﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;

namespace ShortcutMenu.Manager
{
    public class ElementFactoryManage : ManagerBase
    {
        /// <summary>
        /// Key:工厂对应的元素
        /// </summary>
        private Dictionary<Type, ElementFactory> _factorys = new Dictionary<Type, ElementFactory>();

        private static ElementFactoryManage elementFactoryManage;

        public ElementFactoryManage()
        {
            elementFactoryManage = this;
        }

        public override void initialize()
        {
            _factorys.Add(typeof(ApplyElement), new ApplyFactory());
        }

        /// <summary>
        /// 创建元素
        /// </summary>
        /// <typeparam name="TElement">指定元素</typeparam>
        /// <typeparam name="TData">指定数据</typeparam>
        /// <param name="data">元素对应数据</param>
        public static TElement Create<TElement, TData>(TData data)
            where TElement : FrameworkElement
            where TData : ElementDataBase
        {
            var factory = (dynamic)elementFactoryManage._factorys[typeof(TElement)];
            return (TElement)factory.Create(data);
        }
    }
}
